package sncf.client;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimerTask;

import sncf.utils.AdminUtils;
import sncf.utils.Referential;

public class SaveTask extends TimerTask {

	@Override
	public void run() {
		Date now = new Date();
		SimpleDateFormat dateFormatter = new SimpleDateFormat(
				"dd/MM/yyyy HH:mm");
		System.out.println("===== START SAVING TASK at "
				+ dateFormatter.format(now) + " =====");
		try {
			Referential ref = Referential.getInstance();

			// save alert file
			ref.saveAndPurgeAlertTrainList();
			ref.addTimeToNextSaveDate(Calendar.DAY_OF_MONTH, 1);
		} catch (Exception e) {
			e.printStackTrace();
			AdminUtils.notifySystemAdmin(e);
		} finally {
			System.out.println("===== END SAVING TASK ======");
		}
	}

}
